﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Ruandao.HostServer;

namespace Ruandao.Foundation
{
    public class DynamicPathModule : IHttpModule
    {
        #region IHttpModule 成员

        public void Dispose()
        {}

        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);
        }

        void context_BeginRequest(object sender, EventArgs e)
        {
            //取得原始URL, 屏蔽掉参数
            HttpContext context = ((HttpApplication)sender).Context;
            string _url = context.Request.RawUrl;

            if (! SiteWare.Current.Ware.IsDynamicPath(_url) ) return;

            string file = SiteWare.Current.SiteWareMapPath(_url);

            context.Response.ContentType = Ruandao.Misc.UtilityFunction.MimeType(_url);
            context.Response.WriteFile(file);
            context.Response.End();
        }

        #endregion
    }
}
